﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IRepository;
using Spring.Data.Common;
using Infrastructure;
using System.Data;
using Models;

namespace RepositoryMSSQL
{
    public class LogRepository : ILogRepository
    {
        public void CreateLog(EventLog log)
        {
            string strUpd = "insert into event_log(Event_id, action_type, action_time, operator, remark) "
                + " values(@id, @actionType, @actionTime, @actionBy, @remark)";

            IDbParameters p = DBHelper.SpringDBTemplate.CreateDbParameters();
            p.Add("id", DbType.String).Value = log.EventID;
            p.Add("actionType", DbType.String).Value = log.ActionType;
            p.Add("actionTime", DbType.DateTime).Value = log.ActionTime;
            p.Add("actionBy", DbType.String).Value = log.Operator;
            if (log.Remark.Length > 2000)
                log.Remark = log.Remark.Substring(0, 2000);
            p.Add("remark", DbType.String).Value = log.Remark;

            DBHelper.SpringDBTemplate.ExecuteNonQuery(CommandType.Text, strUpd, p);
        }
    }
}
